import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';

// 查询所有系统用户
export function getAllUser() {
    return request.get<AjaxResponse['userData']>(HttpUrl.getAllUser);
}

// 更新系统用户
export function updateUser(data: AjaxRequest['updateUser']) {
    return request.put(HttpUrl.updateUser, data);
}

// 更新系统用户角色
export function updateUserRoleApi(userId: string, roleIds: string[]) {
    return request.put(HttpUrl.updateUserRoleApi, { userId, roleIds });
}

// 查询所有系统角色
export function getAllRole() {
    return request.get<AjaxResponse['roleData']>(HttpUrl.getAllRole);
}

// 添加系统角色
export function addRolesPermission(role: string, roleName: string, permissions: string[]) {
    return request.post(HttpUrl.addRolesPermission, { role, roleName, permissions });
}

// 更新系统角色权限
export function updateRolesPermission(role: string, permissions: string[]) {
    return request.put(HttpUrl.updateRolesPermission, { role, permissions });
}

// 删除系统角色
export function deleteRolesPermission(id: string) {
    return request.del(HttpUrl.deleteRolesPermission, { params: { id } });
}

// 查询所有系统权限
export function getAllPermission() {
    return request.get<AjaxResponse['permissionData']>(HttpUrl.getAllPermission);
}

/* *******************************字典******************************* */
// 获取系统全部字典参数
export function getDictionaryList() {
    return request.get<AjaxResponse['dictionaryList']>(HttpUrl.getDictionaryList);
}

// 导入字典
export function importDictionary(data: AjaxRequest['dictionary'][]) {
    return request.post(HttpUrl.importDictionary, data);
}

// 添加对应参数的字典
export function addDictionary(data: AjaxRequest['dictionary']) {
    return request.post(HttpUrl.addDictionary, data);
}

// 更新对应参数的字典
export function updateDictionary(data: AjaxRequest['dictionary']) {
    return request.put(HttpUrl.updateDictionary, data);
}

// 更新对应字典的角色权限
export function updateDictionaryRoles(data: { dictionaryId: string; roles: string[] }) {
    return request.put(HttpUrl.updateDictionaryRoles, { ...data });
}

// 更新全部字典的角色权限
export function updateAllDictionaryRoles(selected: string[], roles: string[]) {
    return request.put(HttpUrl.updateAllDictionaryRoles, { selected, roles });
}

// 删除对应参数的字典
export function deleteDictionary(ids: string[]) {
    return request.del(HttpUrl.deleteDictionary, { params: { ids } });
}

/* *******************************配置******************************* */
// 获取系统全部配置参数
export function getSystemConfig() {
    return request.get<System>(HttpUrl.getSystemConfig);
}
// 更新系统采购配置参数
export function updateSystemPurchaseConfig(field: string, data: any) {
    return request.post(HttpUrl.updateSystemPurchaseConfig, { field, data });
}
// 删除系统采购配置参数
export function deleteSystemPurchaseConfig(field: string, index: number) {
    return request.put(HttpUrl.deleteSystemPurchaseConfig, { field, index });
}

// 更新系统打印配置参数
export function updateSystemPrintConfig(type: 'OWN' | 'OEM', data: printConfig) {
    return request.post(HttpUrl.updateSystemPrintConfig, { type, data });
}
// 删除系统打印配置参数
export function deleteSystemPrintConfig(field: string, index: number) {
    return request.put(HttpUrl.deleteSystemPrintConfig, { field, index });
}
